<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="制令单代码">
              <a-input placeholder="请输入制令单代码" v-model="queryParam.commandCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="客户">
              <a-input placeholder="请输入客户" v-model="queryParam.cusName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料阶别">
              <a-select v-model="queryParam.lineType" defaultValue="SMT" placeholder="请选择" default-value="0">
                <a-select-option value="SMT">SMT</a-select-option>
                <a-select-option value="DIP">DIP</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="日期">
                <j-date placeholder="请选择日期" v-model="queryParam.inDate"></j-date>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="结果">
                <a-input placeholder="请输入结果" v-model="queryParam.result"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="类型">
                <a-select v-model="queryParam.checkType" placeholder="请选择" default-value="0">
                  <a-select-option value="抽检">抽检</a-select-option>
                  <a-select-option value="抽测">抽测</a-select-option>
                  <!--                  <a-select-option value="2"></a-select-option>-->
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('抽检抽测表')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <a-button @click="showModal('抽检')" type="primary">抽检打印</a-button>
      <a-button @click="showModal('抽测')" type="primary">抽测打印</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="image" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else @click="showImage(text)" :src="text.split(',')[0]" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <mesChooseCheckLog-modal ref="modalForm" @ok="modalFormOk"></mesChooseCheckLog-modal>
    <a-modal v-model="visibleDetail" title="抽检、抽测记录报告" @ok="visibleDetail = false" width="50%" :footer="null">
      <SpotCheck :type="type" :lineType="lineType" :reportData="reportData"/>
    </a-modal>
    <a-modal v-model="image" title="" @ok="image = false" width="50%" :footer="null">
      <div style="display: flex;align-items: center">
        <div @click="activeImgIndex = index" v-for="(item,index) in imageList" style="width: 25%;padding: 0 10px" :class="index === activeImgIndex ? 'select' : ''">
          <img :src="item" width="100%" height="80px"/>
        </div>
      </div>
      <div style="width: 100%;height: auto;padding-top: 20px">
        <img :src="imageList[activeImgIndex]" width="100%" height="auto"  style="max-height: 500px"/>
      </div>
    </a-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import MesChooseCheckLogModal from './modules/MesChooseCheckLogModal'
import JDate from '@/components/jeecg/JDate.vue'
import SpotCheck from '@views/inspect/SpotCheck'

export default {
  name: "MesChooseCheckLogList",
  mixins:[JeecgListMixin, mixinDevice],
  components: {
    SpotCheck,
    JDate,
    MesChooseCheckLogModal
  },
  data () {
    return {
      image: false,
      imageList:[],
      imageUrl: '',
      activeImgIndex:0,
      description: '抽检抽测表管理页面',
      visibleDetail: false,
      type: '',
      lineType:'',// 线别
      reportData: [],
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key:'rowIndex',
          width:60,
          align:"center",
          customRender:function (t,r,index) {
            return parseInt(index)+1;
          }
        },
        {
          title:'创建人',
          align:"center",
          dataIndex: 'createBy'
        },
        {
          title:'创建日期',
          align:"center",
          dataIndex: 'createTime',
          customRender:function (text) {
            return !text?"":(text.length>10?text.substr(0,10):text)
          }
        },
        {
          title:'所属部门',
          align:"center",
          dataIndex: 'sysOrgCode'
        },
        {
          title:'制令单id',
          align:"center",
          dataIndex: 'commandId'
        },
        {
          title:'制令单代码',
          align:"center",
          dataIndex: 'commandCode'
        },
        {
          title:'客户',
          align:"center",
          dataIndex: 'cusName'
        },
        {
          title:'日期',
          align:"center",
          dataIndex: 'inDate',
          customRender:function (text) {
            return !text?"":(text.length>10?text.substr(0,10):text)
          }
        },
        {
          title:'工序',
          align:"center",
          dataIndex: 'workType'
        },
        {
          title:'机型',
          align:"center",
          dataIndex: 'mecType'
        },
        {
          title:'线别',
          align:"center",
          dataIndex: 'lineType'
        },
        {
          title:'站别',
          align:"center",
          dataIndex: 'staType'
        },
        {
          title:'检验数量',
          align:"center",
          dataIndex: 'checkNum'
        },
        {
          title:'检测项目',
          align:"center",
          dataIndex: 'checkPro'
        },
        {
          title:'结果',
          align:"center",
          dataIndex: 'result'
        },
        {
          title:'类型',
          align:"center",
          dataIndex: 'checkType'
        },
        {
          title:'人员id',
          align:"center",
          dataIndex: 'userId'
        },
        {
          title:'人员姓名',
          align:"center",
          dataIndex: 'userName'
        },
        {
          title:'不良数',
          align:"center",
          dataIndex: 'badNum'
        },
        {
          title:'处理结果',
          align:"center",
          dataIndex: 'dealResult'
        },
        {
          title:'备注',
          align:"center",
          dataIndex: 'remark'
        },
        {
          title: '质检图片',
          dataIndex: 'attr1',
          align:"center",
          scopedSlots: { customRender: 'image' },
        },
        {
          title: '操作',
          dataIndex: 'action',
          align:"center",
          // fixed:"right",
          width:147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/inspect/mesChooseCheckLog/list",
        delete: "/inspect/mesChooseCheckLog/delete",
        deleteBatch: "/inspect/mesChooseCheckLog/deleteBatch",
        exportXlsUrl: "/inspect/mesChooseCheckLog/exportXls",
        importExcelUrl: "inspect/mesChooseCheckLog/importExcel",
      },
      dictOptions:{},
    }
  },
  mounted() {
    this.queryParam.lineType = 'SMT'
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    showImage(imageUrl){
      this.image = true
      this.imageList = []
      this.imageList = imageUrl.split(',')
      this.activeImgIndex = 0
      console.log(111,this.imageList)
      // this.imageUrl = imageUrl
    },
    initDictConfig(){
    },
    showModal(type) {
      if(!this.queryParam.lineType){
        return this.$message.error('请先选择物料阶别')
      }
      this.lineType = this.queryParam.lineType
      this.type = type === '抽测' ? '1' : '2'
      let printList = []
      this.selectionRows.forEach(item=>{
        if (item.checkType === type){
          printList.push(item)
        }
      })
      this.reportData = printList
      this.visibleDetail = true;
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
.select {
  position: relative;
  /*width:81px;*/
  height:110px;
  /*margin: 0 auto;*/
  display: flex;
  align-items: center;
  text-align: center;
  line-height: 110px;
  color: #4ABE84;
  background-color: #fff;
  box-shadow:0px 2px 7px 0px rgba(85,110,97,0.35);
  border-radius:7px;
  border:1px solid rgba(74,190,132,1);
}
.select:before {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  border: 17px solid #4ABE84;
  border-top-color: transparent;
  border-left-color: transparent;
}
.select:after {
  content: '';
  width: 5px;
  height: 12px;
  position: absolute;
  right: 6px;
  bottom: 6px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-left-color: transparent;
  transform: rotate(45deg);
}
</style>